D:\git\skunkworks\herald-for-cpp\herald-tests\targetidentifier-tests.cpp
Line | Count | Source |
1 | | // Copyright 2020-2021 Herald Project Contributors |
2 | | // SPDX-License-Identifier: Apache-2.0 |
3 | | // |
4 | | |
5 | | #include <memory> |
6 | | #include <vector> |
7 | | |
8 | | #include "catch.hpp" |
9 | | |
10 | | #include "herald/herald.h" |
11 | | |
12 | 1 | TEST_CASE("datatypes-targetidentifier-ctor-default", "[datatypes][targetidentifier][ctor][default]") { |
13 | 1 | SECTION("datatypes-targetidentifier-ctor-default") { |
14 | 1 | herald::datatype::TargetIdentifier t1; |
15 | 1 | |
16 | 1 | REQUIRE(((std::string)t1).size() == 0); |
17 | 1 | } |
18 | 1 | } |
19 | | |
20 | 1 | TEST_CASE("datatypes-targetidentifier-ctor-data", "[datatypes][targetidentifier][ctor][data]") { |
21 | 1 | SECTION("datatypes-targetidentifier-ctor-data") { |
22 | 1 | herald::datatype::Data d{std::byte('a'),6}; |
23 | 1 | herald::datatype::TargetIdentifier t1(d); |
24 | 1 | |
25 | 1 | herald::datatype::Data out = (herald::datatype::Data)t1; |
26 | 1 | REQUIRE(d == out); |
27 | 1 | } |
28 | 1 | } |
29 | | |
30 | 1 | TEST_CASE("datatypes-targetidentifier-ctor-copy", "[datatypes][targetidentifier][ctor][copy]") { |
31 | 1 | SECTION("datatypes-targetidentifier-ctor-copy") { |
32 | 1 | herald::datatype::Data d1{std::byte('a'),6}; |
33 | 1 | herald::datatype::Data d2{std::byte('a'),6}; |
34 | 1 | herald::datatype::TargetIdentifier t1(d1); |
35 | 1 | herald::datatype::TargetIdentifier t2(d2); |
36 | 1 | |
37 | 1 | herald::datatype::Data t1out = (herald::datatype::Data)t1; |
38 | 1 | herald::datatype::Data t2out = (herald::datatype::Data)t2; |
39 | 1 | REQUIRE(t1 == t2); |
40 | 1 | REQUIRE(&t1 != &t2); |
41 | 1 | REQUIRE(t1out == t2out); |
42 | 1 | } |
43 | 1 | } |
44 | | |
45 | 1 | TEST_CASE("datatypes-targetidentifier-comparison", "[datatypes][targetidentifier][comparison]") { |
46 | 1 | SECTION("datatypes-targetidentifier-comparison") { |
47 | 1 | herald::datatype::Data d{std::byte('a'),6}; |
48 | 1 | herald::datatype::TargetIdentifier t1(d); |
49 | 1 | herald::datatype::TargetIdentifier t2(d); |
50 | 1 | |
51 | 1 | herald::datatype::Data d3{std::byte('b'),6}; |
52 | 1 | herald::datatype::TargetIdentifier t3(d3); |
53 | 1 | |
54 | 1 | herald::datatype::Data t1out = (herald::datatype::Data)t1; |
55 | 1 | herald::datatype::Data t2out = (herald::datatype::Data)t2; |
56 | 1 | herald::datatype::Data t3out = (herald::datatype::Data)t3; |
57 | 1 | |
58 | 1 | REQUIRE(t1 == t2); |
59 | 1 | REQUIRE(!(t1 != t2)); |
60 | 1 | REQUIRE(t1 != t3); |
61 | 1 | REQUIRE(!(t1 == t3)); |
62 | 1 | REQUIRE(&t1 != &t2); |
63 | 1 | REQUIRE(t1out == t2out); |
64 | 1 | REQUIRE(t1out != t3out); |
65 | 1 | |
66 | 1 | // Test Data equality operator |
67 | 1 | REQUIRE(t1 == t1out); |
68 | 1 | REQUIRE(t1out == t1); |
69 | 1 | REQUIRE(!(t1 != t1out)); |
70 | 1 | REQUIRE(!(t1out != t1)); |
71 | 1 | |
72 | 1 | // hash codes |
73 | 1 | REQUIRE(t1.hashCode() == t2.hashCode()); |
74 | 1 | REQUIRE(t1.hashCode() != t3.hashCode()); |
75 | 1 | |
76 | 1 | // string representation comparison |
77 | 1 | REQUIRE(((std::string)t1) == ((std::string)t2)); |
78 | 1 | REQUIRE(((std::string)t1) != ((std::string)t3)); |
79 | 1 | } |
80 | 1 | } |